package com.wlhse.service.impl;

import com.github.pagehelper.PageHelper;
import com.wlhse.dao.CheckRecordDao;
import com.wlhse.dao.EmployeeManagementDao;
import com.wlhse.dao.ProblemListDao;
import com.wlhse.dto.inDto.ProblemListInDto;
import com.wlhse.dto.outDto.CheckRecordRectRecord;
import com.wlhse.dto.outDto.ProblemListOutDto;
import com.wlhse.entity.ProblemSourcePojo;
import com.wlhse.service.ProblemListService;
import com.wlhse.util.GetCurrentUserIdUtil;
import com.wlhse.util.state_code.NR;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.List;

@Service("ProblemListServiceImpl")
public class ProblemListServiceImpl implements ProblemListService {



    @Resource
    private ProblemListDao problemListDao;

    @Resource
    private CheckRecordDao checkRecordDao;

    @Resource
    private GetCurrentUserIdUtil getCurrentUserIdUtil;

    @Override
    public String ProblemListPuls(ProblemListInDto problemListInDto,Integer num, Integer size, HttpServletRequest request) {

        Integer id = getCurrentUserIdUtil.getUserId(request);

        // 可能有多个权限
        List<String> Rolecodes = checkRecordDao.getRoleCodes(id);
        // 取最高的权限
        String Rolecode = Rolecodes.get(0);

        String C_Code = problemListInDto.getCompanyCode();
        if (C_Code.equals("")||C_Code==null) {
            if("2009".equals(Rolecode)){
                C_Code = checkRecordDao.getCurrentCompany(id);
                problemListInDto.setCompanyCode(C_Code.substring(0,4));
            }
        }
        int total = problemListDao.queryProblemListPuls(problemListInDto).size();
        PageHelper.startPage(num,size);

        List<ProblemListOutDto> list = problemListDao.queryProblemListPuls(problemListInDto);
        return NR.r(list,total,num);
    }

    @Override
    public String ProblemListPuls2(ProblemListInDto problemListInDto,Integer num, Integer size, HttpServletRequest request) {
        Integer id = getCurrentUserIdUtil.getUserId(request);

        // 可能有多个权限
        List<String> Rolecodes = checkRecordDao.getRoleCodes(id);
        // 取最高的权限
        String Rolecode = Rolecodes.get(0);

        String C_Code = problemListInDto.getCompanyCode();
        if (C_Code.equals("")||C_Code==null) {
            if("2009".equals(Rolecode)){
                C_Code = checkRecordDao.getCurrentCompany(id);
                problemListInDto.setCompanyCode(C_Code.substring(0,4));
            }
        }
        int total = problemListDao.queryProblemListPuls2(problemListInDto).size();
        PageHelper.startPage(num,size);

        List<ProblemListOutDto> list = problemListDao.queryProblemListPuls2(problemListInDto);
        return NR.r(list,total,num);
    }
}
